/**
 * javaScript函数
 * $Id: functions.js 235 2011-01-06 14:38:21Z bwanglei@gmail.com $
 */

/**
 * 后台移动模块
 */
$(function() {
	$(".m_title").bind('mouseover',function() {
		$(this).css("cursor","move")
	});

	var $show = $("#loader_message_b");
	var $list = $("#right_modules");

	$list.sortable({
		opacity: 0.6,
		revert: true,
		cursor: 'move',
		handle: '.m_title',
		update: function() {
			var new_order = [];
			$list.children(".modules").each(function() {
				new_order.push(this.title);
			});
			var newid = new_order.join(',');
			$.ajax({
				type: "post",
				url: "./sidebar_module.php?action=neworderlist",
				data: { new_order: newid},
				beforeSend: function() {
					$show.html("正在更新");
				},
				success: function(msg) {
					$show.html(msg);
				}
			});
		}
	});
});

/**
 * 显示和隐藏添加标签
 */
function show_hidde_id (id) {
	var ele = document.getElementById(id);
	ele.style.display = (ele.style.display == 'none') ? '' : 'none';
}

/**
 * 添加模块
 */
function add_module(title) {
	var rm = document.getElementById('right_modules');
	var $show = $("#loader_message_b");
	$.ajax({
		type: "post",
		url: "./sidebar_module.php?action=addorderlist",
		data: { add_name: title},
		beforeSend: function() {
			$show.html("正在更新");
		},
		success: function(msg) {
			$show.html('更新完成');
			//msg = eval('('+msg+')');
			//var add_html = '<div class="modules" title="'+title+'"><div class="m_title">Mdule:'+msg.title+'</div><p>'+msg.title+'</p></div>';
			$('#right_modules').append(msg);
		}
	});
}

/**
 * 显示模块信息
 */
function sh_w_info(w_name) {
	var div_name = 'm_info_'+w_name;
	if ($('#'+div_name).css('display')=='none' || $('#'+div_name).css('display')==undefined) {
		$('#'+div_name).css('display','block');
		$('#s_h_'+w_name).html('<a href="javascript:;" onclick="sh_w_info(\''+w_name+'\');">隐藏</a>');
	} else {
		$('#'+div_name).css('display','none');
		$('#s_h_'+w_name).html('<a href="javascript:;" onclick="sh_w_info(\''+w_name+'\');">展开</a>');
	}
}

/**
 * 删除模块
 */
function del_module(w_name) {
	var $show = $("#loader_message_b");
	$.ajax({
		type: "post",
		url: "./sidebar_module.php?action=delorderlist",
		data: { del_name: w_name},
		beforeSend: function() {
			$show.html("正在删除");
		},
		success: function(msg) {
			if (msg == 'true') {
				$show.html('删除成功');
				$('#'+w_name+'_w').remove();
			} else {
				$show.html('删除失败');
			}
		}
	});
}

/**
 * 添加标签在写文章页面
 */
function add_tag(tag_list,tag) {
	var tag_list = document.getElementById(tag_list);
	var new_tag = document.getElementById(tag).value;
	tag_list.innerHTML += ('<div><input type="checkbox" id="id_for_'+new_tag+'" name="tags_article[]" value="'+new_tag+'" checked /><label for="id_for_'+new_tag+'">'+new_tag+'</label></div>');
}

/*
 * 更新模块信息
 */
function u_info_widgets(name,t_url) {
	var $show = $("#loader_message_b");
	var params = $('#'+name).formSerialize();
	params = decodeURIComponent(params, true);
	$.ajax({
		url: t_url,
		type: 'post',
		data: params,
		beforeSend: function() {
			$show.html("正在更新");
		},
		success: function(msg) {
			if (msg=='true') $show.html('更新完成');
		}
	});
}
